home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / VideoToolbox 97.08.16 / VideoToolboxSources / AfterDark.c next >
Encoding:
C/C++ Source or Header  |  1997-01-22  |  3.7 KB  |  133 lines  |  [TEXT/CWIE]

  1. /* AfterDark.c
  2.  
  3. error=AfterDarkDisable();
  4. error=AfterDarkEnable();
  5.  
  6. Disable and later re-enable the popular screen saver, AfterDark. An error code is
  7. returned if the relevant Gestalt selectors are not installed, i.e. no
  8. AfterDark-compatible screen saver is present.
  9.  
  10. Written by David Brainard, based on documentation supplied by Berkeley Systems
  11. Mac Tech Support, brklysystm@aol.com. Ask them for the AfterDarkGestalt.h file.
  12.  
  13. The interface to the screen saver is generic. Any screen saver that installs the
  14. same Gestalt selectors would be controlled by these two routines, but we haven't
  15. tested that.
  16.  
  17. SEE ALSO:
  18. IsFileSharingOn.c
  19.  
  20. HISTORY:
  21. 6/15/95    dhb        Wrote it.
  22. 6/16/95    dhb        Don't call procedure on PPC, as it causes a crash.    
  23. 6/20/95    dhb        Make it work on PPC, use symbol GENERATING68K.
  24. 6/21/95    dhb        Conditional compiles so that it will still work on 68K.
  25. 6/23/95 dgp        Removed the stuff that was MATLAB-specific. Renamed
  26.                             variables to make the code more self documenting.
  27. 6/23/95    dhb        Added necessary stuff from AfterDarkGestalt.h.
  28.                             Include VideoToolbox.h.
  29.                             Move prototypes to VideoToolbox.h.
  30. 5/28/96 dgp        Changed <VideoToolbox.h> to  "VideoToolbox.h"
  31. 1/22/97 dhb   Added IsAfterDarkEnabled.
  32. */
  33.  
  34. #include "VideoToolbox.h"
  35.  
  36. // Gestalt called with 'SAVR' selector returns longword bitmask.
  37. #define gestaltScreenSaverAttr 'SAVR'
  38. enum {
  39.     gestaltSaverTurnedOn = 0,                        /* saver enabled/disabled. */
  40.     gestaltSaverAsleep,                                    /* saver currently asleep. */
  41.     gestaltSaverDemoMode,                                /* saver sleeping in demo mode. */
  42.     gestaltSaverPasswordMode,                        /* saver sleeping in password-protected mode. */
  43.     gestaltAppDrawingDisabled                        /* Quickdraw drawing disallowed between module animation frames. */
  44. };
  45.  
  46. // Gestalt called with 'SAVC' selector returns a pointer
  47. // to a procedure.  Pass the appropriate command
  48. #define gestaltScreenSaverControl 'SAVC'
  49. enum SaverCommand {
  50.     gestaltSaverWakeUp,
  51.     gestaltSaverSleep,
  52.     
  53.     /* defined in AD 2.0x and later */
  54.     gestaltSaverOn,
  55.     gestaltSaverOff,
  56.     
  57.     /* defined for AD 3.0 and later */
  58.     gestaltSysIQOn,
  59.     gestaltSysIQOff,
  60.     
  61.     gestaltForceShort = 257
  62. };
  63. typedef short SaverCommand;
  64. typedef pascal OSErr (*SaverControlProcPtr) (SaverCommand command);
  65.  
  66. static OSErr AfterDarkCommand(SaverCommand command);
  67.  
  68. #if !GENERATING68K
  69.     enum {
  70.         uppSaverProcInfo=kPascalStackBased
  71.              | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  72.              | STACK_ROUTINE_PARAMETER(1,SIZE_CODE(sizeof(SaverCommand)))
  73.     };
  74. #endif
  75.  
  76.  
  77. OSErr AfterDarkEnable(void)
  78. {
  79.     return AfterDarkCommand(gestaltSaverOn);    
  80. }
  81.  
  82.  
  83. OSErr AfterDarkDisable(void)
  84. {
  85.     return AfterDarkCommand(gestaltSaverOff);    
  86. }
  87.  
  88. Boolean IsAfterDarkEnabled(void)
  89. {
  90.     OSErr error;
  91.     long response;
  92.  
  93.     // Make sure the screen saver is installed, return FALSE if not.
  94.     error=Gestalt(gestaltScreenSaverAttr,&response);
  95.     if(error)return FALSE;
  96.  
  97.     if (response & (0x0001 << gestaltSaverTurnedOn)) {
  98.         return TRUE;
  99.     }
  100.     else {
  101.         return FALSE;
  102.     }
  103. }
  104.  
  105. static OSErr AfterDarkCommand(SaverCommand command)
  106. {
  107.     OSErr error;
  108.     long response;
  109.     SaverControlProcPtr saverProcPtr;
  110.     #if !GENERATING68K
  111.         UniversalProcPtr saverUPP=NULL;
  112.     #endif
  113.  
  114.     // Make sure the screen saver is installed, return if not.
  115.     error=Gestalt(gestaltScreenSaverAttr,&response);
  116.     if(error)return error;    
  117.     
  118.     // Get a pointer to the screen saver's control procedure
  119.     error=Gestalt(gestaltScreenSaverControl,(long *)&saverProcPtr);
  120.     if(error)return error;    
  121.     
  122.     // Ask the control procedure to perform the command
  123.     #if GENERATING68K
  124.         error=(*saverProcPtr)(command);
  125.     #else
  126.         saverUPP=NewRoutineDescriptor((ProcPtr)saverProcPtr,uppSaverProcInfo,kM68kISA);
  127.         if(saverUPP==NULL)return 1;    // Memory allocation failed.
  128.         error=(OSErr)CallUniversalProc(saverUPP,uppSaverProcInfo,command);
  129.         DisposeRoutineDescriptor(saverUPP);
  130.     #endif
  131.     return error;
  132. }
  133.